package com.qiwx.pigeon.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.data.CageStatusConfig;
import com.qiwx.pigeon.data.params.FertilizeParam;
import com.qiwx.pigeon.data.params.LoseEggParam;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @description
 * @Author qiwx
 * @Date 2020-06-10 17:05
 * 损失选项 包括不孵蛋 踩破蛋 无蛋
 **/
public class LoseEggOptionView extends LinearLayout {
    @BindView(R.id.rb_bad)
    RadioButton rbBad;
    @BindView(R.id.rb_broken_egg)
    RadioButton rbBrokenEgg;
    @BindView(R.id.rb_wudan)
    RadioButton rbWudan;
    @BindView(R.id.not_fudan)
    RadioGroup notFudan;
    @BindView(R.id.rb_number0)
    RadioButton rbNumber0;
    @BindView(R.id.rb_number1)
    RadioButton rbNumber1;
    @BindView(R.id.rb_number2)
    RadioButton rbNumber2;
    @BindView(R.id.rb_number3)
    RadioButton rbNumber3;
    @BindView(R.id.rg_number)
    RadioGroup rgNumber;
    @BindView(R.id.cb_empty)
    CheckBox cbEmpty;

    public LoseEggOptionView(Context context) {
        this(context, null);
    }

    public LoseEggOptionView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LoseEggOptionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
        initEvent();
    }

    private void initView(Context context) {
        LayoutInflater mInflater = LayoutInflater.from(context);
        View view = mInflater.inflate(R.layout.lose_egg_option, null);
        ButterKnife.bind(this, view);
        addView(view);
        resetOptions();


    }

    private void initEvent() {
        rbBad.setOnCheckedChangeListener((group, ischeck) -> {
            if (ischeck) {
                rbNumber2.setChecked(true);
                cbEmpty.setChecked(true);
            }
        });
        rbBrokenEgg.setOnCheckedChangeListener((group, ischeck) -> {
            if (ischeck) {
                rbNumber2.setChecked(true);
                cbEmpty.setChecked(true);
            }
        });
        rbWudan.setOnCheckedChangeListener((group, ischeck) -> {
            if (ischeck) {
                rbNumber2.setChecked(true);
                cbEmpty.setChecked(true);
            }
        });

    }

    public LoseEggParam getParam() {
        LoseEggParam param = new LoseEggParam();
        int loseAmount = 0;//损失数量 默认是2
        if (rbNumber0.isChecked()) {
            loseAmount = 0;
        } else if (rbNumber1.isChecked()) {
            loseAmount = 1;
        } else if (rbNumber2.isChecked()) {
            loseAmount = 2;
        } else if (rbNumber3.isChecked()) {
            loseAmount = 3;
        }
        param.setAmount(loseAmount);
        param.setBad(rbBad.isChecked() ? 1 : 0);
        param.setBreaken(rbBrokenEgg.isChecked() ? 1 : 0);
        param.setWd(rbWudan.isChecked() ? 1 : 0);
        param.setIs_empty(cbEmpty.isChecked() ? 1 : 0);
        return param;

    }


    //重置选项
    public void resetOptions() {
        rbBad.setChecked(true);
        rbNumber2.setChecked(true);
        cbEmpty.setChecked(true);
    }
}
